package com.thundersoft.musicbox;

import android.app.Application;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.util.Log;

/**
 * 备注:
 *
 * @author hmb
 * @version 1.0
 * @since 2015/11/19 13:43
 */
public class MusicApplication extends Application implements ServiceConnection {

    private static Context context;
    private static MusicManager musicManager;
    private static final String TAG ="MusicApplication";

    @Override
    public void onCreate() {
        Log.d(TAG, "Application onCreate");
        super.onCreate();
        context = this;

        Intent intent = new Intent(this, MusicService.class);
        startService(intent);
        bindService(intent, this, Context.BIND_AUTO_CREATE);
        //MusicContext.initMusicData();

    }

    public static Context getContext() {
        return context;
    }


    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        Log.d(TAG,"服务已连接"+name);

        MusicService.MusicBinder binder = (MusicService.MusicBinder) service;
        musicManager = binder.getMusicManager();
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        Log.d(TAG,"服务已断开");
    }

    public static MusicManager getMusicManager(){
        return musicManager;
    }

}
